﻿using System;
using System.Web;
using OPM.Library.Models;
using OPM.Models;
using OPM.Models.BaseModel;
using OPM.ServiceOfficer;

namespace OPM.Class
{
    public static class WSO
    {
        #region Service Officer

        public static string ChangePassword(string old_password, string new_password)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.ChangePassword(U.Token, old_password, new_password);
            return resultStr;
        }

        public static string CheckOtherName(string other_name)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.CheckOtherName(other_name);
            return resultStr;
        }
        public static string GetCountEachState(string other_name)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetCountEachState(other_name);
            return resultStr;
        }

        public static string CheckUsername(string username)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.CheckUsername(username);
            return resultStr;
        }

        public static string GetContact(string operating_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetContact(U.Token, operating_id);
            return resultStr;
        }

        public static GetOfficerProfileLogs[] GetOfficerProfileLogs(string officer_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetOfficerProfileLogs(U.Token, officer_id, skip.Value, take.Value);
            GetOfficerProfileLogs[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetOfficerProfileLogs[]>(resultStr);
            return result;
        }

        public static string AddContact(string case_id, string channel_id, string objective_id,
            string type_id,
            string status_id, string cont_start, string cont_end, string summary, string detail, string cont_is_secret,
            string account_id,
            string cont_type, string cont_gender_id, string cont_title, string cont_firstname, string cont_lastname,
            string cont_citizen_id, string cont_contact_detail, string cont_country_id, string cont_address,
            string cont_subdistrict_id, string cont_district_id, string cont_province_id, string cont_postcode,
            string cont_birthday, string cont_remark, string cont_is_defective, int cont_number, string cont_is_victim, string severity_id, string priority_id,
            string secret_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.AddContact(U.Token, case_id, channel_id, objective_id, type_id,
                status_id, cont_start, cont_end, summary, detail, cont_is_secret, account_id,
                cont_type, cont_gender_id, cont_title, cont_firstname, cont_lastname,
                cont_citizen_id, cont_contact_detail, cont_country_id, cont_address,
                cont_subdistrict_id, cont_district_id, cont_province_id, cont_postcode,
                cont_birthday, cont_remark, cont_is_defective, cont_number, cont_is_victim,
                severity_id, priority_id, secret_id);
            return resultStr;
        }

        public static string AddCustomer(string case_id, string cust_type, string cust_gender_id, string cust_title, string cust_firstname,
            string cust_lastname, string cust_citizen_id, string cust_contact_detail, string cust_country_id, int cust_number, string cust_address,
            string cust_subdistrict_id, string cust_district_id, string cust_province_id, string cust_postcode, string cust_birthday, string cust_remark,
            string cust_is_defective, string cust_is_public)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.AddCustomer(U.Token, case_id, cust_type, cust_gender_id, cust_title, cust_firstname,
             cust_lastname, cust_citizen_id, cust_contact_detail, cust_country_id, cust_number, cust_address,
             cust_subdistrict_id, cust_district_id, cust_province_id, cust_postcode, cust_birthday, cust_remark,
             cust_is_defective, cust_is_public);
            return resultStr;
        }

        public static string AddOperating(string case_id, string type_id, string status_id,
            string terminal_org_id, string terminal_owner_id,
            string date_opened, string date_closed, string summary, string detail, string severity_id,
            string priority_id, string secret_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.AddOperating(U.Token, case_id, type_id, status_id, terminal_org_id, terminal_owner_id,
                date_opened, date_closed, summary, detail, severity_id, priority_id, secret_id);
            return resultStr;
        }

        public static string DuplicateCase(string case_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.DuplicateCase(U.Token, case_id);
            return resultStr;
        }

        public static string EditCase(string case_id, string objective_id, string type_id,
            string terminal_type_id, string status_id, string date_opened, string date_closed,
            string channel_incoming_id, string call_back, string channel_outgoing_id,
            string summary, string detail, string defendent, string date_occurrenced_from, string date_occurrenced_to,
            string time_occurrenced, string country_id, string case_area, string subdistrict_id, string district_id, string province_id,
            string postcode, string latitude, string longitude, string case_value, string is_in_court, string remark,
            string is_secret, string priority_id, string severity_id, string secret_id, string org_master_id,
            OPM.ServiceOfficer.ArrayOfString org_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.EditCase(U.Token, case_id, objective_id, type_id,
                terminal_type_id, status_id, date_opened, date_closed,
                channel_incoming_id, call_back, channel_outgoing_id,
                summary, detail, defendent, date_occurrenced_from, date_occurrenced_to,
                time_occurrenced, country_id, case_area, subdistrict_id, district_id, province_id,
                postcode, latitude, longitude, case_value, is_in_court, remark,
                is_secret, priority_id, severity_id, secret_id, org_master_id,
                org_id);
            return resultStr;
        }

        public static string EditContactAccount(string account_id, string cust_type, string cust_gender_id, string cust_title, string cust_firstname,
            string cust_lastname, string cust_citizen_id, string cust_contact_detail, string cust_country_id, int cust_number, string cust_address, string cust_subdistrict_id,
            string cust_district_id, string cust_province_id, string cust_postcode, string cust_birthday, string cust_remark, string cust_is_defective, string cust_is_public)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.EditContactAccount(U.Token, account_id, cust_type, cust_gender_id, cust_title, cust_firstname,
             cust_lastname, cust_citizen_id, cust_contact_detail, cust_country_id, cust_number, cust_address, cust_subdistrict_id,
             cust_district_id, cust_province_id, cust_postcode, cust_birthday, cust_remark, cust_is_defective, cust_is_public);
            return resultStr;
        }

        public static string EditContact(string case_id, string operating_id, string contact_id,
            string channel_id, string objective_id, string type_id, string status_id, string cont_start, string cont_end,
            string cont_is_secret, string account_id, string summary, string detail, string cont_is_victim,
            string severity_id, string priority_id, string secret_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.EditContact(U.Token, case_id, operating_id, contact_id,
                channel_id, objective_id, type_id, status_id, cont_start, cont_end,
                cont_is_secret, account_id, summary, detail, cont_is_victim,
                severity_id, priority_id, secret_id);
            return resultStr;
        }

        public static string EditOperating(string operating_id, string type_id, string status_id,
            string terminal_org_id,
            string terminal_owner_id, string date_opened, string date_closed, string summary, string detail,
            string severity_id,
            string priority_id, string secret_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.EditOperating(U.Token, operating_id, type_id, status_id, terminal_org_id,
                terminal_owner_id, date_opened, date_closed, summary, detail, severity_id,
                priority_id, secret_id);
            return resultStr;
        }

        public static string EditCustomerProfile(string customer_id, string cont_is_secret, string cont_type, string cont_gender_id, string cont_title, string cont_firstname,
            string cont_lastname, string cont_citizen_id, string cont_contact_detail, string cont_country_id, string cont_address, string cont_subdistrict_id, string cont_district_id,
            string cont_province_id, string cont_postcode, string cont_birthday, string cont_remark, int cont_number, string cont_is_defective)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.EditCustomerProfile(U.Token, customer_id, cont_is_secret, cont_type, cont_gender_id, cont_title, cont_firstname,
             cont_lastname, cont_citizen_id, cont_contact_detail, cont_country_id, cont_address, cont_subdistrict_id, cont_district_id,
             cont_province_id, cont_postcode, cont_birthday, cont_remark, cont_number, cont_is_defective);
            return resultStr;
        }

        public static string GetAllProfile()
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetAllProfile(U.Token);
            return resultStr;
        }

        public static GetCase GetCase(string case_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetCase(U.Token, case_id);
            GetCase result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetCase>(resultStr);
            return result;
        }

        public static string GetCaseLogs(string case_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetCaseLogs(U.Token, case_id, skip.Value, take.Value);
            return resultStr;
        }

        public static string GetCaseOfficer(string case_id, string org_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetCaseOfficer(U.Token, case_id, org_id, skip.Value, take.Value);
            return resultStr;
        }

        public static string GetCaseOrganization(string case_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetCaseOrganization(U.Token, case_id);
            return resultStr;
        }

        public static string GetPictureProfile()
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetPictureProfile(U.Token);
            return resultStr;
        }

        public static User GetProfile(GetTokenResult tokenobj)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetProfile(tokenobj.token_id);
            User result = Newtonsoft.Json.JsonConvert.DeserializeObject<User>(resultStr);
            result.GetTokenResult = tokenobj;
            return result;
        }

        public static string GetContactAccount(string account_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetContactAccount(U.Token, account_id);
            return resultStr;
        }

        public static string GetContactAccountCases(string account_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetContactAccountCases(U.Token, account_id, skip.Value, take.Value);
            return resultStr;
        }

        public static string GetContactAccountLogs(string account_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetContactAccountLogs(U.Token, account_id, skip.Value, take.Value);
            return resultStr;
        }

        public static string GetCustomerAddress(string customer_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetCustomerAddress(U.Token, customer_id);
            return resultStr;
        }

        public static string GetCustomerProfile(string customer_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetCustomerProfile(U.Token, customer_id);
            return resultStr;
        }

        public static string GetCustomerProfileCases(string customer_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetCustomerProfileCases(U.Token, customer_id, skip.Value, take.Value);
            return resultStr;
        }

        public static string GetCustomerProfileLogs(string profile_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetCustomerProfileLogs(U.Token, profile_id, skip.Value, take.Value);
            return resultStr;
        }

        public static Groups GetGroups()
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetGroups(U.Token);
            Groups result = Newtonsoft.Json.JsonConvert.DeserializeObject<Groups>(resultStr);
            return result;
        }

        public static GetKnowledgeComments[] GetKnowledgeComments(string knowledge_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetKnowledgeComments(U.Token, knowledge_id, skip.Value, take.Value);
            GetKnowledgeComments[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetKnowledgeComments[]>(resultStr);
            return result;
        }

        public static GetKnowledgeDetail GetKnowledgeDetail(string knowledge_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetKnowledgeDetail(U.Token, knowledge_id);
            GetKnowledgeDetail result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetKnowledgeDetail>(resultStr);
            return result;
        }

        public static GetKnowledges GetKnowledgeSmile(string knowledge_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetKnowledgeSmile(U.Token, knowledge_id);
            GetKnowledges result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetKnowledges>(resultStr);
            return result;
        }

        public static string SetKnowledgeSmile(string content_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.SetKnowledgeSmile(U.Token, content_id);
            return resultStr;
        }

        public static string GetReadKnowledge(string content_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetReadKnowledge(U.Token, content_id);
            return resultStr;
        }

        public static GetKnowledges[] GetKnowledges(string type_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetKnowledges(U.Token, type_id, skip.Value, take.Value);
            GetKnowledges[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetKnowledges[]>(resultStr);
            return result;
        }

        public static string AddKnowledgeComment(string content_id, string comment_text, string ref_comment_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.AddKnowledgeComment(U.Token, content_id, comment_text, ref_comment_id);
            return resultStr;
        }

        public static string EditKnowledgeComment(string comment_id, string content_id, string comment_text, string ref_comment_id = "")
        {
            var s = new OfficerSoapClient();
            var resultStr = s.EditKnowledgeComment(U.Token, comment_id, content_id, comment_text, ref_comment_id);
            return resultStr;
        }

        public static GetMessage[] GetNews()
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetNews(U.Token);
            GetMessage[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetMessage[]>(resultStr);
            return result;
        }

        public static GetMessage GetNewsDetail(string news_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetNewsDetail(U.Token, news_id);
            GetMessage result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetMessage>(resultStr);
            return result;
        }

        public static Notification[] GetNotifys()
        {
            var s = new OfficerSoapClient();
            string resultStr = "";
            try
            {
                resultStr = s.GetNotifies(U.Token);
            }
            catch (Exception e)
            {
                HttpContext.Current.Response.Write("Error: " + e.Message);
                HttpContext.Current.Response.End();
            }
            Notification[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<Notification[]>(resultStr);
            return result;
        }

        public static string GetOfficerProfile(string officer_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetOfficerProfile(U.Token, officer_id);
            return resultStr;
        }

        public static string GetOperating(string operating_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetOperating(U.Token, operating_id);
            return resultStr;
        }

        public static string GetOperatings(string case_id, string select_org_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetOperatings(U.Token, case_id, select_org_id, skip.Value, take.Value);
            return resultStr;
        }

        public static string GetOrganizationAddress(string org_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetOrganizationAddress(U.Token, org_id);
            return resultStr;
        }

        public static GetTimelineHeader[] GetTimelineHeader(string last_get_date_time, string timeline_type = "A",
            int skip = 0, int take = 10)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetTimelineHeader(U.Token, last_get_date_time, timeline_type, skip, take);
            GetTimelineHeader[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<GetTimelineHeader[]>(resultStr);
            return result;
        }

        public static TimelineOperating[] GetTimelineOperating(string cast_id, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.GetTimelineOperating(U.Token, cast_id, skip.Value, take.Value);
            TimelineOperating[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<TimelineOperating[]>(resultStr);
            return result;
        }

        public static GetTokenResult GetToken(string user, string password, AuthenForm authen_from, string ip_address)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.GetToken(user, password, authen_from.ToString(), ip_address);
            GetTokenResult result = !resultStr.StartsWith("\"Err")
                ? Newtonsoft.Json.JsonConvert.DeserializeObject<GetTokenResult>(resultStr)
                : null;
            return result;
        }

        public static string InformAttachment(string case_id,
            string file_name, string file_content, string file_description,
            string doc_type_id, string doc_type, string doc_no, string doc_date,
            string doc_ref_no, string doc_ref_date)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.InformAttachment(U.Token, case_id, file_name, file_content, file_description,
                doc_type_id, doc_type, doc_no, doc_date, doc_ref_no, doc_ref_date);

            return resultStr;
        }

        public static string InformCase(string objective_id, string type_id,
            string terminal_type_id, string status_id,
            string date_opened, string date_closed, string channel_incoming_id, string call_back,
            string channel_outgoing_id, string summary, string detail, string defendent, string used_inform_with,
            string date_occurrenced_from, string date_occurrenced_to, string time_occurrenced, string country_id,
            string case_area, string subdistrict_id, string district_id, string province_id,
            string postcode, string latitude, string longitude, string case_value,
            string is_in_court, string remark, string is_secret, string priority_id,
            string severity_id, string secret_id, string org_master_id, OPM.ServiceOfficer.ArrayOfString org_id,
            string cont_is_secret, string cont_type, string cont_gender_id, string cont_title,
            string cont_firstname, string cont_lastname, string cont_citizen_id, string cont_contact_detail,
            string cont_country_id, string cont_address, string cont_subdistrict_id, string cont_district_id,
            string cont_province_id, string cont_postcode, string cont_birthday, string cont_remark, int cont_number, string cont_is_defective,
            string cont_is_victim, string cust_type, string cust_gender_id, string cust_title,
            string cust_firstname, string cust_lastname, string cust_citizen_id, string cust_contact_detail,
            string cust_country_id, int cust_number, string cust_address, string cust_subdistrict_id,
            string cust_district_id, string cust_province_id, string cust_postcode, string cust_birthday,
            string cust_remark, string cust_is_defective, string cust_is_public)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.InformCase(U.Token, objective_id, type_id, terminal_type_id, status_id,
                date_opened, date_closed, channel_incoming_id, call_back,
                channel_outgoing_id, summary, detail, defendent, used_inform_with,
                date_occurrenced_from, date_occurrenced_to, time_occurrenced, country_id, case_area,
                subdistrict_id, district_id, province_id, postcode,
                latitude, longitude, case_value, is_in_court,
                remark, is_secret, priority_id, severity_id,
                secret_id, org_master_id, org_id, cont_is_secret, cont_type,
                cont_gender_id, cont_title, cont_firstname, cont_lastname,
                cont_citizen_id, cont_contact_detail, cont_country_id, cont_address,
                cont_subdistrict_id, cont_district_id, cont_province_id, cont_postcode,
                cont_birthday, cont_remark, cont_number, cont_is_defective, cont_is_victim, cust_type,
                cust_gender_id, cust_title, cust_firstname, cust_lastname,
                cust_citizen_id, cust_contact_detail, cust_country_id, cust_number,
                cust_address, cust_subdistrict_id, cust_district_id, cust_province_id,
                cust_postcode, cust_birthday, cust_remark, cust_is_defective, cust_is_public);
            return resultStr;
        }

        public static string OperatingAttachment(string case_id,
            string operating_id, string file_name, string file_content,
            string file_description, string doc_type_id, string doc_type, string doc_no,
            string doc_date, string doc_ref_no, string doc_ref_date)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.OperatingAttachment(U.Token, case_id, operating_id, file_name, file_content,
                file_description, doc_type_id, doc_type, doc_no, doc_date, doc_ref_no, doc_ref_date);
            return resultStr;
        }

        public static string RecoveryPassword(string username, string citizen_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.RecoveryPassword(username, citizen_id);
            return resultStr;
        }

        public static string ReleaseToken(string picture_name, string data_url)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.ReleaseToken(U.Token);
            return resultStr;
        }

        public static SearchContact[] SearchContactAccounts(string keyword, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.SearchContactAccounts(U.Token, keyword, skip.Value, take.Value);
            SearchContact[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<SearchContact[]>(resultStr);
            return result;
        }

        public static SearchCustomer[] SearchCustomerProfiles(string keyword, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.SearchCustomerProfiles(U.Token, keyword, skip.Value, take.Value);
            SearchCustomer[] result = Newtonsoft.Json.JsonConvert.DeserializeObject<SearchCustomer[]>(resultStr);
            return result;
        }

        public static string SearchTempCases(string keyword, string temp_code, string date_from,
            string date_to, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.SearchTempCases(U.Token, keyword, temp_code, date_from, date_to,
                skip.Value, take.Value);
            return resultStr;
        }

        public static string SetCloseTempCase(string case_id)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.SetCloseTempCase(U.Token, case_id);
            return resultStr;
        }

        public static string SetPictureProfile(string picture_name, string data_url)
        {
            var s = new OfficerSoapClient();
            var resultStr = s.SetPictureProfile(U.Token, picture_name, data_url);
            return resultStr;
        }

        public static string SearchCases(string keyword, int? skip = null, int? take = null)
        {
            if (!skip.HasValue) skip = 0;
            if (!take.HasValue) take = U.RowPerPage;
            var s = new OfficerSoapClient();
            var resultStr = s.SearchCases(U.Token, keyword, skip.Value, take.Value);
            return resultStr;
        }

        #endregion
    }
}